package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.MyDoGood;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 收到未读点赞数量的资源控制器
 */
@RestController
@RequestMapping("mydogood")
public class MyDoGoodController {
    @Autowired
    private IMyDoGoodService myDoGoodService;

    /**
     * 新增/删除点赞状态
     *
     * @param myDoGood
     * @return
     */
    @PostMapping
    public JSONResult selectDoGoodState(MyDoGood myDoGood) {
        MyDoGood doGood = myDoGoodService.selectDoGoodState(myDoGood);
        if (doGood == null) {
            myDoGoodService.saveDoGoodState(myDoGood);
        } else {
            myDoGoodService.deleteDoGoodState(myDoGood);
        }
        return new JSONResult();
    }

    /**
     * 获取游记的未读点赞的数量
     * @param id
     * @return
     */
    @GetMapping("/{id}/allDoGood")
    public int selectDoGoodCount(@PathVariable Long id){
        return myDoGoodService.selectTravelDoGoodCount(id);
    }

    /**
     * 更新作者的游记点赞状态
     * @param authorId
     * @return
     */
    @GetMapping("{authorId}")
    public JSONResult deleteDoGoodState(@PathVariable Long authorId) {
        myDoGoodService.updateDoGoodForauthorId(authorId);
        return new JSONResult();
    }
}
